﻿using Md.Api.Entity.DapperModels.MdDB;
using Md.Api.Model.Manage.SysPost.Request;
using Md.Dapper.Repositories.Md;

namespace Md.Api.Service.Manage.SysPost;
/// <summary>
/// 添加系统岗位服务
/// </summary>
public class InsertSysPostService : ApiBase<RequestInsertSysPostModel>
{
    /// <summary>
    /// 系统岗位仓储
    /// </summary>
    public SysPostRep sysPostRep { get; set; }
    /// <summary>
    /// 执行
    /// </summary>
    protected override void ExecuteMethod()
    {
        var model = new SysPostModel();

        model.PostCode = Parameter.PostCode;
        model.PostName = Parameter.PostName;
        model.PostSort = Parameter.PostSort;
        model.Status = Parameter.Status;
        model.Remark = Parameter.Remark;
        model.CreateBy = userKey?.ToString();
        model.CreateTime = DateTime.Now;

        var res = sysPostRep.Insert(model);

        if (Convert.ToInt64(res) > 0)
        {
            Result.Data = sysPostRep.GetSysPostByPostId(Convert.ToInt64(res));
        }
        else
        {
            Result.Data = res;
        }
    }
}
